<?php
include_once 'BaseService.php';
include_once $_SERVER ['DOCUMENT_ROOT'] . '/ad/sys/com/model/db/PaysettingDAO.php';
include_once $_SERVER ['DOCUMENT_ROOT'] . '/ad/sys/com/model/util/Util.php';

class PaysettingService extends BaseService {
	
	function __construct() {
		parent::__construct ();
		parent::setTarget ( $this );
	}
	
	public function add() {
		$cpc = $_REQUEST ["cpc"];
		$cpm = $_REQUEST ["cpm"];
		$cpcPublish = $_REQUEST ["cpcPublish"];
		$cpmPublish = $_REQUEST ["cpmPublish"];
		$dao = new PaysettingDAO ();
		$dao->add ( $cpc, $cpm, $cpcPublish, $cpmPublish );
	
	}
	public function addOrUpdate() {
		$cpc = $_REQUEST ["cpc"];
		$cpm = $_REQUEST ["cpm"];
		$cpcPublish = $_REQUEST ["cpcPublish"];
		$cpmPublish = $_REQUEST ["cpmPublish"];
		$dao = new PaysettingDAO ();
		@$result=$dao->getInfo ();
		if(@$result->length>0)
		{
			
		$reuslt=$dao->add ( $cpc, $cpm, $cpcPublish, $cpmPublish );
		}
		else {
		$reuslt=$dao->update ( $cpc, $cpm, $cpcPublish, $cpmPublish );
		}
			$msg = $reuslt =="" ? "設定失敗!":"設定成功";
			echo "{success:true,result:'$reuslt',msg :'$msg'}";
		
	}
	public function getInfo() {
		$dao = new PaysettingDAO ();
		@$result=$dao->getInfo ();
		echo Util::toJson($result);
		//echo "{".Util::toJson($result)."}";
	}
	public function update() {
		$cpc = $_REQUEST ["cpc"];
		$cpm = $_REQUEST ["cpm"];
		$cpcPublish = $_REQUEST ["cpcPublish"];
		$cpmPublish = $_REQUEST ["cpmPublish"];
		$dao = new PaysettingDAO ();
		$dao->update ( $cpc, $cpm, $cpcPublish, $cpmPublish );
	}
}

$service = new PaysettingService ();
$service->__call ( $_GET ["action"], null );
?>